package map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author liyang
 * @version 1.0
 * @package map
 * @file MapDemo2.java
 * @description
 * @time 2024-05-02 17:10
 */
public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("数学",100);
        map.put("生物",50);
        map.put("物理",80);
        System.out.println(map);

//        遍历一组键值对
//        泛型套泛型
        Set<Map.Entry<String,Integer>> entrySet= map.entrySet();
        for (Map.Entry<String,Integer> e:entrySet){
            String key = e.getKey();
            Integer value = e.getValue();
            System.out.println("键："+key+"  值："+value);
        }

        map.forEach((k,v) ->System.out.println(k+":"+v));

    }
}
